<?php
/**
 * General exception
 *
 * This is a base exeption form Elfin framework. Other exception will extend
 * this class for better exception handling proposes.
 *
 * LICENSE: This file is part of Elfin.
 *
 *   Elfin is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Elfin is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Elfin.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Filipe Silva <silvam.filipe@gmail.com>
 * @category Core
 * @license GNU General Public License <http://www.fsf.org/licensing/licenses/gpl.html>
 */

/**
 * General exception
 *
 * This is a base exeption form Elfin framework. Other exceptions will extend
 * this class for better exception handling proposes.
 * @package Elfin
 * @subpackage Exceptions
 */
class GeneralException extends Exception {
    /**
     * Previous exception
     * @var Exception
     */
    private $previous;

    protected $template;

    /**
     * Constructor
     *
     * Creates a new general exception
     * @param String $message The error message
     * @param long $code The error code
     * @param Exception $previous The previous exception if exists
     */
    public function  __construct($message, $code = 0, Exception $previous = null) {
        parent::__construct($message, $code);
        if (!is_null($previous)){
            $this -> previous = $previous;
        }
        $this->template = APP . DS . 'views' . DS . 'errors' . DS . 'general_error.php';
        
    }

    public function  __toString() {
        ob_start();
        include $this->template;
        $output = ob_get_contents();
        ob_end_clean();
        return $output;
    }

}
?>